<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%">
    <el-col>
      <!-- 左侧内容 -->
      <span><i v-if="treeRoot" class="el-icon-office-building" />{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 放置下拉菜单 -->
          <el-dropdown>
            <!-- 内容 -->
            <span>操作
              <i class="el-icon-arrow-down" />
            </span>
            <!-- 具名插槽 -->
            <el-dropdown-menu slot="dropdown">
              <!-- 下拉选项 -->
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!treeRoot" @click.native="editDepartment">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!treeRoot" @click.native="delDepartments">删除部门</el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
    <!-- 右侧内容 -->
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    treeRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    async delDepartments() {
      // 询问用户
      await this.$confirm('是否删除该部门')
      // 发起请求
      await delDepartment(this.treeNode.id)
      // 提示用户、
      this.$message.success('删除成功')
      // 更新页面
      this.$emit('delDepartments')
    },
    // 新增弹窗
    addDepartment() {
      // 通知父组件
      // this.$emit('addDepartment')
      this.$emit('addDepartment', this.treeNode)
    },
    // 编辑弹框
    editDepartment() {
      this.$emit('editDepartment', this.treeNode)
    }
  }
}
</script>

<style>

</style>
